/*********************************************************************************
 *      Copyright:  (C) 2022 Zhang Changxing<ZhangChangxingVIP@163.com>
 *                  All rights reserved.
 *
 *       Filename:  platform_conf.c
 *    Description:  This file defines a structure to store the configuration information \
 *                  for connecting to the MQTT server and completes the platform selection and configuration.
 *                 
 *        Version:  1.0.0(05/1/2022)
 *         Author:  Zhang Changxing <ZhangChangxingVIP@163.com>
 *      ChangeLog:  1, Release initial version on "05/1/2022  01:33:25 AM"
 *                 
 ********************************************************************************/

#ifndef  _CONF_H_
#define  _CONF_H_


typedef struct mqtt_connect_ctx_s
{
    char        host[128];
    int         port;
    char        client_id[128];
    char        username[64];
    char        passwd[128];
    int         keepalive;
    int         platform_flag;/*Used to determine which platform to choose*/
}mqtt_connect_ctx_t;

typedef struct pub_ctx_s
{
    char        pub_topic[128];
    char        pub_message[1024];/*Stores messages to be published*/
    int         pub_flag;/*Flag used to determine if there is data to publish*/   
    int         platform_flag;/*Used to determine which platform to choose*/
    int         connect_flag;
    int         pub_qos;
    int         sum;
}pub_ctx_t;

typedef struct sub_ctx_s
{
    char        sub_topic[128];
    char        sub_message[1024];/*Stores messages for subscriptions*/
    int         sub_flag;/*Used to determine whether messages are delivered to the subscribed topic*/ 
    int         platform_flag;/*Used to determine which platform to choose*/
    int         sub_qos;
}sub_ctx_t;

typedef struct log_ctx_s{
    int     loglevel;/*The level of logging*/
    char    logfile[128];/*Log File Path*/
    int     logsize;/*Log file capacity*/
}log_ctx_t;

typedef struct iotd_ctx_s
{
    mqtt_connect_ctx_t mqtt_connect_ctx;
    pub_ctx_t   pub_ctx;
    sub_ctx_t   sub_ctx;
    log_ctx_t   log_ctx;
}iotd_ctx_t;

enum PLATFORM
{
    ALI, TENGCENT, HUAWEI
};


/****************************************************************************************************
 *   description:   Complete platform selection and configuration
 *          args:   $mqtt:    The configuration information structure pointer that connects the broker
 *  return value:      <0: failure,    =0:ok 
 ****************************************************************************************************/
int inifile_parsing(iotd_ctx_t *iotd_ctx, int platform);

#endif